package com.ocom.company.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ocom.common.entity.company.EntityImportLog;
import com.ocom.common.enums.DataSourceEnum;
import com.ocom.common.enums.MasterSlaveEnum;
import com.ocom.common.resp.Result;
import com.ocom.common.utils.ResultUtil;
import com.ocom.company.dao.IDaoImportLog;
import com.ocom.company.service.ImportLogService;
import com.ocom.mysql.aspect.DataSourceAspect;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * @Description: TODO
 * @Author: 朱晖
 * @Date: 2022年10月8日10:21:43
 **/
@Service
public class ImportLogServiceImpl extends ServiceImpl<IDaoImportLog, EntityImportLog> implements ImportLogService {


	@Override
	@DataSourceAspect(type= DataSourceEnum.PART_DB,isMaster = MasterSlaveEnum.MASTER)
	public Boolean saveImprt(Long companyId,EntityImportLog entityImportLog) {
		return this.save(entityImportLog);
	}

	@Override
	@DataSourceAspect(type= DataSourceEnum.PART_DB,isMaster = MasterSlaveEnum.SLAVE)
	public Result getLogs(Long companyId, Integer page, Integer size) {
		LambdaQueryWrapper<EntityImportLog> queryWrapper = new LambdaQueryWrapper<EntityImportLog>().eq(EntityImportLog::getComId, companyId);
		List<EntityImportLog> list = this.list(queryWrapper);
		if(page==null||page<=0){
			page=1;
		}
		if(size==null||size<=0){
			size=500;
		}
		PageHelper.startPage(page,size);

		PageInfo<EntityImportLog> pageInfo = new PageInfo<>(list);
		HashMap<String, Object> map = new HashMap<>();
		map.put("total", pageInfo.getTotal());
		map.put("list", pageInfo.getList());
		return ResultUtil.success(map);
	}
}
